function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
} 

var isCode = localStorage.getItem('bussinsCode10086')
var code = GetQueryString("code");
var mobile;
var mobileShow;
localStorage.setItem('bussinsCode10086', code)
if (code && isCode != code) {
    $.ajax({
        type: "post",
        url: Url + "/marketing/getPhone.do",
        data: {
            "code": code
        },
        success: function (data) {
           if(data.status==0||data.status==1){
                $('.com').show();
                $('.comTip').text(data.message)
                $('.comsure').off('click')
                if(data.status==0){//没关注
                    $('.comsure').on('click',function(){
                        location.href='https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzA5OTM5NTEwOA==&scene=124#wechat_redirect'
                    })
                }else{//没绑定
                    $('.comsure').on('click',function(){
                        location.href='http://wx.10086.cn/website/personalHome/new/index'
                    })
                }
           }else{
            mobile = data.phone;
            init()
           }
        }
    })
}else{
    location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx43a850f87498127d&redirect_uri=http%3a%2f%2fwx.10086.cn%2fshandong%2fwx%2fmarketYear%2findex.html&response_type=code&scope=snsapi_base&state=123&connect_redirect=1#wechat_redirect";
}

// var mobile= 'DAA16F2BF7A73327BB08A964942D16F6'
// init()

function init() {  
    $.post(Url+'/marketing/initPage.do',{phone:mobile},function(res){
        mobileShow = res.phone;
        if(res.regStatus==1){
            $('.banli').css({ 'background': 'url(./img/btn_go1.png)', 'backgroundSize': '100% 100%' })//已经办理过
        }else{
            $('.banli').on('click',function(){
                $.post(Url+'/marketing/register.do',{phone:mobile},function(res){
                    if(res.success == 'true'){
                        $('.banli').css({ 'background': 'url(./img/btn_go1.png)', 'backgroundSize': '100% 100%' })//已经办理过s
                        $('.register').show();
                        $('.register .phone').text(mobileShow)
                        $('.banli').off('click')
                    }
                })
            })
        }
        $.each(res.businessList, function (i, e) { 
             $('#make'+(i+1)).attr('data-id',e.id)
             $('#make'+(i+1)).attr('data-status',e.status)
             $('#make'+(i+1)).on('click',function(){
                 var status = $('#make'+(i+1)).attr('data-status');
                 var id = $('#make'+(i+1)).attr('data-id');
                //  if(status==1){
                //     $('.com').show();
                //     $('.comTip').text('您已预约过，不能重复预约')
                //  }else{
                    if(id==1){
                        window.location.href = 'https://www.shandong10086.com/weixin/marketYear/yue.html?game=1&id=1';
                    }else if(id==2){
                        window.location.href = 'https://www.shandong10086.com/weixin/marketYear/yue.html?game=1&id=2';
                    }
                //  }

                // $('.com').show();
                // $('.comTip').text('敬请期待')
             })
        });
    })
}

// 登记成功关闭
$('.registersure').on('click',function(){
    $('.register').hide()
}) 
//通用弹窗
$('.comsure').on('click',function(){
    $('.com').hide()
})
//活动规则
$('.rule').on('click',function(){
    window.location.href = 'https://www.shandong10086.com/sdCmosService/activitySupport/preview.do?id=35'
})